package com.uphone.magicleafteacher.pro.activity.listenertrainresult;

import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import com.radish.baselibrary.Intent.IntentData;
import com.radish.baselibrary.Intent.IntentUtils;
import com.radish.baselibrary.utils.LogUtils;
import com.uphone.magicleafteacher.R;
import com.uphone.magicleafteacher.base.mvp.BaseMvpActivity;
import com.uphone.magicleafteacher.pro.activity.PracticeDetailActivity;
import com.uphone.magicleafteacher.util.AudioPlayProgressUtil;
import com.uphone.magicleafteacher.util.CommonUtil;
import com.uphone.magicleafteacher.util.DateUtils;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.ResponseBody;

/**
 * Time: 2019/10/29
 */
public class ListenerTrainResultActivity extends BaseMvpActivity<ListenerTrainResultPresenter> implements ListenerTrainResultContract.View {

    @BindView(R.id.tv_score1)
    TextView tvScore1;
    @BindView(R.id.tv_score2)
    TextView tvScore2;
    @BindView(R.id.tv_score3)
    TextView tvScore3;
    @BindView(R.id.tv_score4)
    TextView tvScore4;
    @BindView(R.id.tv_score5)
    TextView tvScore5;
    @BindView(R.id.tv_score6)
    TextView tvScore6;
    @BindView(R.id.iv_play)
    ImageView ivPlay;
    @BindView(R.id.sb_audio)
    SeekBar sbAudio;
    @BindView(R.id.tv_duration)
    TextView tvDuration;
    @IntentData
    private int id;
    @IntentData
    private String title = "";
    private AudioPlayProgressUtil audioPlayUtils;

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected void initBundle() {

    }

    @Override
    protected int initLayout() {
        return R.layout.activity_listener_train_result;
    }

    @Override
    protected void initView() {
        audioPlayUtils = new AudioPlayProgressUtil();
    }

    @Override
    protected void initTitle() {
        LogUtils.e("title:" + title);
        initTitle(CommonUtil.getStr(title));
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {
        audioPlayUtils.setProgressListener(new AudioPlayProgressUtil.ProgressListener() {
            @Override
            public void start() {
                ivPlay.setSelected(true);
            }

            @Override
            public void progress(int progress, int currentDuration, int totalDuration) {
                if (progress != sbAudio.getProgress())
                    sbAudio.setProgress(progress);
                tvDuration.setText("" + DateUtils.getTimeFormLong(currentDuration));
            }

            @Override
            public void completion() {
                ivPlay.setSelected(false);
                tvDuration.setText("00:00:00");
            }

            @Override
            public void stop() {
                ivPlay.setSelected(false);

            }
        });
    }

    @OnClick({R.id.iv_play, R.id.iv_practice})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_play:
                if (view.isSelected()) {
                    audioPlayUtils.stop();
                } else {
                    audioPlayUtils.play(getResources().getString(R.string.music_1));
                }
                break;
            case R.id.iv_practice:
                IntentUtils.getInstance().with(this, PracticeDetailActivity.class)
                        .putString("audioPath", "")
                        .start();
                break;
        }
    }

    @Override
    public void updateView(ResponseBody responseBean, int status) {

    }

    @Override
    public void updateView(Object t) {

    }
}
